package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class zzzzz2025102302PeachActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btn_one, btn_two, btn_three,btn_four, btn_five, btn_six, btn_exit;
    private int count = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.zzzzz2025102302_activity_peach);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.zzzzz2025102302001main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        init();
    }
    private void init() {
        btn_one = findViewById(R.id.zzzzz2025102302002btn_one);
        btn_two = findViewById(R.id.zzzzz2025102302003btn_two);
        btn_three = findViewById(R.id.zzzzz2025102302004btn_three);
        btn_four = findViewById(R.id.zzzzz2025102302005btn_four);
        btn_five = findViewById(R.id.zzzzz2025102302006btn_five);
        btn_six = findViewById(R.id.zzzzz2025102302007btn_six);
        btn_exit = findViewById(R.id.zzzzz2025102302008btn_exit);
        btn_one.setOnClickListener(this);
        btn_two.setOnClickListener(this);
        btn_three.setOnClickListener(this);
        btn_four.setOnClickListener(this);
        btn_five.setOnClickListener(this);
        btn_six.setOnClickListener(this);
        btn_exit.setOnClickListener(this);
    }
    @Override
    public void onClick(View view) {
        if(view.getId() == R.id.zzzzz2025102302002btn_one)
            info(btn_one);
        if(view.getId() == R.id.zzzzz2025102302003btn_two)
            info(btn_two);
        if(view.getId() == R.id.zzzzz2025102302004btn_three)
            info(btn_three);
        if(view.getId() == R.id.zzzzz2025102302005btn_four)
            info(btn_four);
        if(view.getId() == R.id.zzzzz2025102302006btn_five)
            info(btn_five);
        if(view.getId() == R.id.zzzzz2025102302007btn_six)
            info(btn_six);
        else if(view.getId() == R.id.zzzzz2025102302008btn_exit) {
            returnData();
        }
    }
    private void info(Button btn) {
        count++;
        btn.setVisibility(View.INVISIBLE);
        Toast.makeText(zzzzz2025102302PeachActivity.this, "已摘到" + count + "个桃子", Toast.LENGTH_SHORT).show();
    }
    private void returnData() {
        Intent intent = new Intent();
        intent.putExtra("count", count);
        setResult(1, intent);
        zzzzz2025102302PeachActivity.this.finish();
    }
    public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK&& event.getRepeatCount() == 0) {
            returnData();
        }
        return false;
    }
}